home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
-
- <xsl:key name="teams" match="result/home" use="@team"/>
- <xsl:key name="teams" match="result/away" use="@team"/>
- <xsl:key name="opposition" match="result/home" use="../away/@team"/>
- <xsl:key name="opposition" match="result/away" use="../home/@team"/>
- <xsl:key name="wins" match="result/away[@score > ../home/@score]" use="@team"/>
- <xsl:key name="wins" match="result/home[@score > ../away/@score]" use="@team"/>
- <xsl:key name="draws" match="result/away[@score = ../home/@score]" use="@team"/>
- <xsl:key name="draws" match="result/home[@score = ../away/@score]" use="@team"/>
-
- <xsl:template match="/">
- <html>
- <head>
- <title>
- <xsl:value-of select="/results/@nation"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="/results/@sponsor"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="/results/@league"/>
- <xsl:text> (condensed)</xsl:text>
- </title>
- </head>
- <body>
- <h3>
- <xsl:value-of select="/results/@nation"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="/results/@sponsor"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="/results/@league"/>
- <xsl:text> (condensed)</xsl:text>
- </h3>
- <table border="0" bgcolor="Black" cellspacing="1" style="font-family: Courier New, Courier, monospace; font-size: 12;">
- <tr bgcolor="Silver">
- <th>Pos</th>
- <th>Team</th>
- <th>Pld</th>
- <th width="20">W</th>
- <th width="20">D</th>
- <th width="20">L</th>
- <th width="20">F</th>
- <th width="20">A</th>
- <th width="20">GD</th>
- <th width="20">Pts</th>
- </tr>
- <!-- apply template to each distinct team -->
- <xsl:apply-templates select="(/results/result/home|/results/result/away)[generate-id(.) = generate-id(key('teams',@team))]">
- <!-- sort primarily on points -->
- <xsl:sort select="(count(key('wins',@team)) * 3) + (count(key('draws',@team)))" data-type="number" order="descending"/>
- <!-- secondary sort by goal difference -->
- <xsl:sort select="sum(key('teams',@team)/@score) - sum(key('opposition',@team)/@score)" data-type="number" order="descending"/>
- <!-- final sort on goals scored -->
- <xsl:sort select="sum(key('teams',@team)/@score)" data-type="number" order="descending"/>
- </xsl:apply-templates>
- </table>
- <sub>
- <xsl:text>(Results up to and including </xsl:text>
- <!-- find max date - don't rely on results being sorted -->
- <xsl:variable name="last-date">
- <xsl:apply-templates select="/results/result/@date[1]" mode="find-max">
- <xsl:sort select="translate(.,'-','')" data-type="number" order="ascending"/>
- </xsl:apply-templates>
- </xsl:variable>
- <xsl:value-of select="concat(substring($last-date,9,2),'/',substring($last-date,6,2),'/',substring($last-date,1,4))"/>
- <xsl:text>)</xsl:text>
- </sub>
- </body>
- </html>
- </xsl:template>
-
- <xsl:template match="home|away">
- <!-- store any nodesets used more than once -->
- <xsl:variable name="games" select="key('teams',@team)"/>
- <!-- calculate anything that is used more than once -->
- <!-- saves processing keys excessively -->
- <xsl:variable name="played" select="count($games)"/>
- <xsl:variable name="wins" select="count(key('wins',@team))"/>
- <xsl:variable name="draws" select="count(key('draws',@team))"/>
- <xsl:variable name="goals-for" select="sum($games/@score)"/>
- <xsl:variable name="goals-against" select="sum(key('opposition',@team)/@score)"/>
- <!-- now display the table row -->
- <tr bgcolor="#{substring('FFFFFF8AF7D6',((position() mod 2)*6)+1,6)}">
- <!-- league position -->
- <td align="right"><xsl:value-of select="position()"/></td>
- <!-- team name -->
- <td><xsl:value-of select="@team"/></td>
- <!-- games played -->
- <td align="right"><xsl:value-of select="$played"/></td>
- <!-- wins -->
- <td align="right"><xsl:value-of select="$wins"/></td>
- <!-- draws -->
- <td align="right"><xsl:value-of select="$draws"/></td>
- <!-- losses -->
- <td align="right"><xsl:value-of select="$played - $wins - $draws"/></td>
- <!-- goals for -->
- <td align="right"><xsl:value-of select="$goals-for"/></td>
- <!-- goals against -->
- <td align="right"><xsl:value-of select="$goals-against"/></td>
- <!-- goal difference -->
- <td align="right"><xsl:value-of select="$goals-for - $goals-against"/></td>
- <!-- points -->
- <td align="right"><xsl:value-of select="($wins * 3) + $draws"/></td>
- </tr>
- </xsl:template>
-
- <xsl:template match="@date" mode="find-max">
- <xsl:if test="position() = last()">
- <xsl:value-of select="."/>
- </xsl:if>
- </xsl:template>
-
- </xsl:stylesheet>